package ru.gerunn.silent.io;

import java.io.IOException;
import java.io.ObjectInputStream;

import javax.net.ssl.SSLSocket;

import ru.gerunn.silent.message.Message;

public class SocketReader implements Reader {

	private final ObjectInputStream reader;

	public SocketReader(final SSLSocket socket) throws ReaderException {
		try {
			reader = new ObjectInputStream(socket.getInputStream());
		} catch (IOException e) {
			throw new ReaderException(e);
		}
	}

	public Message read() throws ReaderException {
		try {
			return (Message) reader.readObject();
		} catch (ClassNotFoundException e) {
			throw new ReaderException(e);
		} catch (IOException e) {
			throw new ReaderException(e);
		}
	}

}
